package com.hong.service_user.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hong.fy_common_commomutil.common.result.Result;
import com.hong.fy_common_commomutil.common.utils.IpUtil;
import com.hong.fy_model.model.cart.CartEntity;
import com.hong.fy_model.model.user.UserEntity;
import com.hong.fy_model.vo.user.LoginVo;
import com.hong.service_cart_client.CartFeignClient;
import com.hong.service_user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author wqh
 * @email 1601709391@qq.com
 * @date 2022-06-16 21:42:56
 */
@RestController
@RequestMapping("/user")
@Api(value = "用户接口", tags = "用户接口")
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 用户注册
     * @param user
     * @return
     */
    @ApiOperation(value = "用户注册,注意用户名不能重复")
    @PostMapping("/register")
    public Result register(@RequestBody UserEntity user){

        return Result.fail("注册失败");
    }

    /**
     * 用户账号密码登录
     */
    @ApiOperation(value = "用户账号密码登录")
    @PostMapping("/loginByPwd")
    public Result loginByPwd(@RequestBody LoginVo loginVo, HttpServletRequest request) {
        loginVo.setIp(IpUtil.getIpAddr(request));
        Map<String, Object> info = userService.loginByPwd(loginVo);
        return Result.ok(info);
    }

    /**
     * 用户手机号码登录
     */
    @ApiOperation(value = "用户手机号码登录")
    @PostMapping("/loginByPhone")
    public Result loginByPhone(@RequestBody LoginVo loginVo, HttpServletRequest request) {
        loginVo.setIp(IpUtil.getIpAddr(request));
        Map<String, Object> info = userService.loginByPhone(loginVo);
        return Result.ok(info);
    }


}
